<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :cities="cities" :hotCities="hotCities" :checkLetter="checkLetter"></city-list>
    <city-alphablet :cities="cities" @letterChange="letterChange"></city-alphablet>
  </div>
</template>

<script>
  import CityHeader from './components/Header'
  import CitySearch from './components/Search'
  import CityList from './components/List'
  import CityAlphablet from './components/Alphablet'
  import axios from 'axios'

  export default {
    name: 'City',
    components: {
      CityHeader,
      CitySearch,
      CityList,
      CityAlphablet
    },
    data () {
      return {
        cities: {},
        hotCities: [],
        checkLetter: ''
      }
    },
    methods: {
      getCityInfo: function () {
        axios.get('static/mock/city.json').then(this.handleCiy)

      },
      handleCiy: function (res) {
        console.log(res)
        res = res.data
        if (res.ret && res.data) {
          const data = res.data
          this.cities = data.cities
          this.hotCities = data.hotCities
        }
      },
      letterChange: function (value) {
        this.checkLetter = value
      }
    },
    mounted: function () {
      this.getCityInfo()
    }
  }
</script>

<style scoped>

</style>
